#include "CG_location.h"


CG_location::CG_location() : x(LOCATION_UNDEFINED), y(LOCATION_UNDEFINED) 
{
}
		

CG_location::CG_location(const float new_x, const float new_y)
{
	if(new_x < 0 || new_y < 0)
	{
		this->x = LOCATION_UNDEFINED;
		this->y = LOCATION_UNDEFINED;
	}
	this->x = new_x;
	this->y = new_y;
}
		

CG_location::CG_location(const CG_location& loc) : x(loc.x), y(loc.y)
{
}


CG_location::~CG_location()
{
}


CG_location& CG_location::operator=(const CG_location& new_loc)
{
	if(this == &new_loc)
	{
		return *this;
	}
	this->x = new_loc.x;
	this->y = new_loc.y;

	return *this;
}
		

float CG_location::get_x() const
{
	return this->x;
}
		

float CG_location::get_y() const
{
	return this->y;
}


bool CG_location::set_x(const float loc_x)
{
	if(loc_x < 0)
	{
		return false;
	}
	this->x = loc_x;

	return true;
}
		

bool CG_location::set_y(const float loc_y)
{
	if(loc_y < 0)
	{
		return false;
	}
	this->y = loc_y;

	return true;
}
		

float CG_location::calc_distance(const float loc_x, const float loc_y)
{
	if(loc_x < 0 || loc_y < 0 || this->x == LOCATION_UNDEFINED || this->y == LOCATION_UNDEFINED)
	{
		return LOCATION_UNDEFINED;
	}

	return sqrt((float)(((this->x - loc_x) * (this->x - loc_x)) + ((this->y - loc_y) * (this->y - loc_y))));
}
		

float CG_location::calc_distance(const CG_location& loc)
{
	if(loc.x == LOCATION_UNDEFINED || loc.y == LOCATION_UNDEFINED || this->x == LOCATION_UNDEFINED || this->y == LOCATION_UNDEFINED)
	{
		return LOCATION_UNDEFINED;
	}

	return sqrt((float)(((this->x - loc.x) * (this->x - loc.x)) + ((this->y - loc.y) * (this->y - loc.y))));
}
